rm(list = ls(all = TRUE))

### PATHS ##############################
dataIn <- "./data/22-topics_100_iterations_dtm_results/estimates/22_topics_avg_word_probs.csv"
dataOut <- "./data"
#######################################

for (no.words in seq(10,50,5)) { # max is 50
    # read data
    data <- read.csv(dataIn, stringsAsFactors=FALSE)
    
    # reduce to selected vocab size
    data <- data[1:no.words,]
    
    # turn columns into single-cell word list
    a <- apply(data, 2, function(x) paste(x, collapse=" "))
    
    # write to txt file
    fname <- file.path(dataOut, paste0("DTM_word_list_22_topics_top_",no.words,"_words.txt"))
    write(a, fname)
    
}
